package _3sort.src;


/**
 * @className: _7countSort_shengji
 * @description:
 * @author: myself
 * @date: 2025/7/18 20:50
 * @version: 0.1
 * @since: JDK17
 */
//适合有限个大小的数组
public class _7countSort {
    public static void main(String[] args) {

    }

    public static void SortFunction(int[] nums) {
        int max = nums[0];
        //找出其中的最大值
        for (int num : nums) {
            max = Math.max(max, num);
        }
        //创建一个相关的数组
        int[] maxCountArray = new int[max + 1];
        //遍历原始数组，进行新数组的遍历增值
        for (int num : nums) {
            maxCountArray[num]++;
        }
        //遍历新数组
        int index=0;
        for (int i = 0; i < maxCountArray.length; i++) {
            for (int j = 0; j < maxCountArray[i]; j++) {
                nums[index++] = i;
            }
        }
    }
}
